//
//  CaSiViewController.m
//  NhomThuy
//
//  Created by HOCVIEN on 1/27/15.
//  Copyright (c) 2015 t3h. All rights reserved.
//

#import "CaSiViewController.h"
#import "ManagerData.h"
#import "CaSiCollectionViewCell.h"
#import "BaiHatTheoCaSiViewController.h"
@interface CaSiViewController ()<UICollectionViewDelegate,UICollectionViewDataSource,UICollectionViewDelegateFlowLayout>

@end

@implementation CaSiViewController

- (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil
{
    self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil];
    if (self) {
        // Custom initialization
    }
    return self;
}

- (void)viewDidLoad
{
    [super viewDidLoad];
	// Do any additional setup after loading the view.
    self.clSingerList.delegate = self;
    self.clSingerList.dataSource = self;
}
- (void)viewWillAppear:(BOOL)animated{
    [UINavigationBar appearance];
    [self.navigationController.navigationBar setBarTintColor:[[ManagerData defaultManager] setBackgroundColorForNavi]];
    [self.navigationController.navigationBar setTintColor:[[ManagerData defaultManager] setTintColorForNavi]];
    self.navigationItem.titleView = [[ManagerData defaultManager]setImageTitleForNavi];
}
#pragma mark UICollectionView
- (NSInteger)collectionView:(UICollectionView *)collectionView numberOfItemsInSection:(NSInteger)section{
    return [ManagerData defaultManager].singerList.count;
}
- (UICollectionViewCell *)collectionView:(UICollectionView *)collectionView cellForItemAtIndexPath:(NSIndexPath *)indexPath{
    NSString *cellID=@"casi_cell_id";
    CaSiCollectionViewCell *cell = [collectionView dequeueReusableCellWithReuseIdentifier:cellID forIndexPath:indexPath];
    if(!cell){
        [collectionView registerClass:[CaSiCollectionViewCell class] forCellWithReuseIdentifier:cellID];
    }
    NSDictionary *detail = [ManagerData defaultManager].singerList[indexPath.item];
    cell.hinhCaSi.image=[UIImage imageNamed:[detail objectForKey:@"singer-avatar"]];
    cell.tenCaSi.text= [[detail objectForKey:@"singer-name"] capitalizedString];
    //[cell setBackgroundColor:[UIColor grayColor]];
    return cell;
}
- (NSInteger)numberOfSectionsInCollectionView:(UICollectionView *)collectionView{
    return 1;
}
- (CGSize)collectionView:(UICollectionView *)collectionView layout:(UICollectionViewLayout *)collectionViewLayout sizeForItemAtIndexPath:(NSIndexPath *)indexPath{
    CGSize size = CGSizeMake((collectionView.frame.size.width - 26 )/3, 110);
    return size;
}
- (CGSize)collectionView:(UICollectionView *)collectionView layout:(UICollectionViewLayout *)collectionViewLayout referenceSizeForFooterInSection:(NSInteger)section{
    CGSize size = CGSizeMake(collectionView.frame.size.width, 90);
    return size;
}
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender{
    if([segue.identifier isEqualToString:@"casi_detail"]){
        BaiHatTheoCaSiViewController *detail = (BaiHatTheoCaSiViewController*)segue.destinationViewController;
        NSArray *selected =self.clSingerList.indexPathsForSelectedItems;
        NSIndexPath *i = selected[0];
        NSDictionary *singer = [[ManagerData defaultManager].singerList objectAtIndex:i.item];
        detail.singerID = [singer objectForKey:@"singer-id"];
        detail.singerName = [singer objectForKey:@"singer-name"];
    }
}
- (void)didReceiveMemoryWarning
{
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

@end
